﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：GroupInfo
// 文件功能描述：班组管理
//
// 
// 创建标识：2012-02-14 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class GroupInfo
    {
        /// <summary>
        /// 主键，班组ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 班组名称
        /// </summary>
        public string Group_Name
        {
            get;
            set;
        }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get;
            set;
        }
        /// <summary>
        /// 所属食堂
        /// </summary>
        public int Node_ID
        {
            get;
            set;
        }

        private DataAccessGroup dar;
        private int Groupcount;
        public int _Groupcount
        {
            get { return Groupcount; }
        }
        public GroupInfo(bool isgetcount)
        {
            dar = new DataAccessGroup();
            if (isgetcount)
            {
                Groupcount = GetGroupCount();
            }
        }
        public GroupInfo()
        { }

        /// <summary>
        /// 获取班组数量
        /// </summary>
        /// <returns></returns>
        private int GetGroupCount()
        {
            return dar.GetGroupCount();
        }

        /// <summary>
        /// 获取班组信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<GroupInfo> SelGroupInfo(int pagesize, int startindex, string strquery)
        {
            IList<GroupInfo> grolist = new List<GroupInfo>();
            GroupInfo groinfo;
            DataSet ds = dar.SelGroupInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                groinfo = new GroupInfo()
                {
                    ID = Convert.ToInt32(item["ID"]),
                    Group_Name = item["Group_Name"].ToString(),
                    Remark = item["Remark"].ToString()
                };
                grolist.Add(groinfo);
            }
            return grolist;
        }

        /// <summary>
        /// 获取食堂信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public DataSet GetWarehouse_ID()
        {
            DataSet ds = dar.GetWarehouse_ID();
            return ds;
        }

        /// <summary>
        /// 获取食堂信息1（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public DataSet GetWarehouse_ID1()
        {
            DataSet ds = dar.GetWarehouse_ID1();
            return ds;
        }

        /// <summary>
        /// 保存班组(新增界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveGroup(GroupInfo gro)
        {
            object[] gropara = new object[] { gro.Node_ID, gro.Group_Name, gro.Remark };
            return dar.SaveGroup(gropara);
        }

        /// <summary>
        /// 保存班组(修改界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveGroupEdit(GroupInfo gro)
        {
            object[] gropara = new object[] { gro.ID, gro.Node_ID, gro.Group_Name, gro.Remark };
            return dar.SaveGroupEdit(gropara);
        }

        /// <summary>
        /// 删除班组
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteGroup(string id)
        {
            return dar.DeleteGroup(id);
        }

        /// <summary>
        /// 根据编号获取一条班组信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public GroupInfo GetGroupInfoOne(string id)
        {
            dar = new DataAccessGroup();
            DataSet ds = dar.GetGroupInfoOne(id);
            GroupInfo info = new GroupInfo();
            info.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
            info.Node_ID = int.Parse(ds.Tables[0].Rows[0]["Node_ID"].ToString());
            info.Group_Name = ds.Tables[0].Rows[0]["Group_Name"].ToString();
            info.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
            return info;
        }

        public static string GetGroupNameById(int id)
        {
            return DataAccessGroup.GetGroupNameById(id);
        }

        public DataSet GetNodeID()
        {
            dar = new DataAccessGroup();
            return dar.GetNodeID();
        }
    }
}
